﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter21.Models.ThreadingIssues
{
    using System.Diagnostics;

    public class StateObject
    {
        private int state = 5;
        private object syncBoot = new object();

        public void ChangeState(int loop)
        {
            lock (syncBoot)
            {
                if (state == 5)
                {
                    state++;
                    Trace.Assert(state == 6, "在" + loop + "循环后，出现争用条件");
                }
                state = 5;
            }
        }
    }
}
